import { nextTick } from './util/nextTick.js'
let has = {}
let queue = []

function flushSchedulerQueue() {
  for(let cb of queue) {
    console.log(cb);
    cb.run()
  }
  queue = []
  has = {}
}

export function queueWatcher(watcher) {
  const id = watcher.id
  // 去重
  if(has[id] === undefined) {
    queue.push(watcher)
    has[id] = true
    // 异步调用
    nextTick(flushSchedulerQueue)
  }
}